/**
 * @Description :文章相关 api
 * @author : August_xiao
 * @date : 2022-02-26 20:52
 */
import axios from '@/utils/axios'

const articleApi = {
  //博客列表
  homeList: '/xiang-blog/common/home',
  // 博客详情
  articleDetails: '/xiang-blog/common/getDetailCommon',
  // 获取文章评论
  getComments: '/xiang-blog/commentdist/getComment',
  //获得推荐文章信息
  getRecommend: '/xiang-blog/common/get-recommend',
  // 对用户进行ip、地址记录
  getRecordUserUrl: '/xiang-blog/login-log/record-user',
  // 获取访问用户总数
  getLoginCountUrl: '/xiang-blog/login-log/get-login-count',
  // 获取所有数据带分页参数
  listByQueryUrl: '/xiang-blog/common/list-by-query'
}

// 评论相关api
const commentsApi = {
  //评论文章
  repComment: '/xiang-blog/commentdist/sakuraSave'
}

/**
 * 获取首页列表
 * @param params current=1 &size=10
 * @returns {AxiosPromise}
 */
const getArticleList = (params) => {
  return axios.get(articleApi.homeList, params)
}

/**
 * 获取详细博客
 * @param params id
 * @returns {AxiosPromise}
 */
const getDetails = (params) => {
  return axios.get(articleApi.articleDetails, params)
}

/**
 * 获取文章评论
 * @param params 文章id
 * @returns {AxiosPromise}
 */
const getComments = (params) => {
  return axios.get(articleApi.getComments, params)
}

/**
 * //获得推荐文章信息
 * @param params id
 * @returns {AxiosPromise}
 */
const getRecommend = (params) => {
  return axios.get(articleApi.getRecommend, params)
}

const getRecordUser = (params) => {
  return axios.post(articleApi.getRecordUserUrl, params)
}

const getLoginCount = () => {
  return axios.get(articleApi.getLoginCountUrl)
}

/**
 * 评论  {
 *   "blogId": 202203100903085111,
 *   "parentId": -1,
 *   "context": "测试",
 *   "user":{
 *     "email": "1850697175@qq.com",
 *     "name": "想想",
 *     "avatar": "https://gw.alipayobjects.com/zos/rmsportal/BiazfanxmamNRoxxVxka.png"
 *   }
 * }
 * @param params
 * @returns {AxiosPromise}
 */
const repComment = (params) => {
  return axios.post(commentsApi.repComment, params)
}

const listByQuery = (params) => {
  return axios.get(articleApi.listByQueryUrl, params)
}

export {
  getArticleList,
  getDetails,
  getComments,
  getRecommend,
  repComment,
  getRecordUser,
  getLoginCount,
  listByQuery
}
